// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property([cc.SpriteFrame])
    frames: cc.SpriteFrame[] = [];

    sprite: cc.Sprite = null;
    index: number = 0;
    interval: number = 0.1;
    
    onLoad () {
        this.sprite = this.getComponent(cc.Sprite)
    }

    start () {
        // this.schedule(this.onTimer, this.interval)
    }

    onTimer(){
        if(this.frames.length === 0) return;

        this.sprite.spriteFrame = this.frames[this.index];

        this.index++;
        if(this.index >= this.frames.length){
            this.index = 0;
        }
    }

    // update (dt) {}

    onDestroy(){
        this.unschedule(this.onTimer)
    }
}
